<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    li {
        list-style: none;
    }

    [v-cloak] {
        display: none;
    }
</style>

<body>
    <div id="app" v-cloak>
        <h1>{{fullName}}</h1>
        <button @click="changeName">修改fullname</button>
    </div>
</body>
<script src="../js/http_cdn.bootcdn.net_ajax_libs_vue_2.6.6_vue.js"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            firstName: "Dowson",
            lastName: "Jack",
        },
        computed: {
            // 计算属性的原生写法，本身是个get，set，在调用的时候调用的是其get()方法
            // 修改的时候调用set方法，参数是即将修改的值;
            fullName: {
                set(val) {
                    console.log(val + "set方法")
                    this.firstName = val
                },
                get() {
                    console.log("fullName get方法")
                    return this.firstName + " " + this.lastName
                }
            },

        },
        methods:{
            // 修改计算属性的值,会触发计算属性set方法
            changeName(){
                this.fullName = 'fullName'
            }
        }
    })
</script>

</html>
